import {defineStore} from "pinia";

export const useSystemStore = defineStore('system', {
    state: () => ({
        routerHistory: [],
        menuTree: []
    }),
    actions: {
        async routerPush(route) {
            if (this.routerHistory.filter(item => item.name === route.name).length === 0) {
                if (this.routerHistory.length >= 10) {
                    this.routerHistory.splice(0, 1)
                }
                this.routerHistory.push({
                    name: route.name,
                    title: route.meta.title,
                    icon: route.meta.icon
                })
            }

        },
        async removeAt(index) {
            this.routerHistory.splice(index, 1)
        },
        async initMenuTree(menuTree) {
            this.menuTree = menuTree
        }
    }
})
